package ui;

import dao.CustomDaoimpl;
import dao.ICustom;
import factory.CustomDaoFactory;
import services.CustomServicempl;
import vo.Custom;
import vo.Furniture;

import java.util.List;
import java.util.Scanner;

public class CustomLogin {
    static CustomServicempl customServicempl=new CustomServicempl();//获取对客户表的具体操作类
    static Scanner scanner=new Scanner(System.in);
    public static void Login(){ //客户表页面
            System.out.println("1,添加数据");
            System.out.println("2,删除数据");
            System.out.println("3,修改数据");
            System.out.println("4,查询数据");
            System.out.println("5,查询所有数据");
            System.out.println("0,返回上一级");
            System.out.println("请输入你的选择");
            int fuctionNumbre=scanner.nextInt();
            switch (fuctionNumbre){
                case 1:
                    if(add()){
                        System.out.println("添加成功");
                    }else {
                        System.out.println("添加失败");
                    }
                case 2:
                    if(delet()){
                        System.out.println("删除完成");
                    }else {
                        System.out.println("删除失败");
                    }
                case 3:
                    if(modify()){
                        System.out.println("修改完成");
                    }else {
                        System.out.println("修改失败");
                    }
                case 4:
                    Custom custom=getcustombyid();
                    System.out.println(custom);
                    break;
                case 5:
                    List<Custom> list=getall();
                    for(Custom custom1:list){
                        System.out.println(custom1);
                    }
                    break;
                case 0:
                    System.out.println("返回");
            }
    }
    private static boolean add(){
        Scanner scanner=new Scanner(System.in);
        System.out.println("请输入客户姓名:");
        String name=scanner.nextLine();
        System.out.println("请输入客户电话:");
        String number=scanner.nextLine();
        System.out.println("请输入客户地址:");
        String address=scanner.nextLine();
        System.out.println("请输入客户购买家具的编号:");
        int id=scanner.nextInt();
        System.out.println("请输入客户购买家具的数量");
        int count=scanner.nextInt();
        System.out.println("请输入客户购买家具的时间");
        String time=scanner.nextLine();
        Custom custom=new Custom(name,number,address,id,count,time);
        return customServicempl.add(custom);
    }
    private static boolean delet(){  //通过客户姓名删除信息
        Scanner scanner=new Scanner(System.in);
        System.out.println("请输入客户姓名:");
        String name=scanner.nextLine();
        Custom custom=new Custom(name);
        return customServicempl.delete(custom);
    }
    private static boolean modify(){  //传入新的客户信息
        Scanner scanner=new Scanner(System.in);
        System.out.println("请输入客户姓名:");
        String name=scanner.nextLine();
        System.out.println("请输入客户电话:");
        String number=scanner.nextLine();
        System.out.println("请输入客户地址:");
        String address=scanner.nextLine();
        System.out.println("请输入客户购买家具的编号:");
        int id=scanner.nextInt();
        System.out.println("请输入客户购买家具的数量");
        int count=scanner.nextInt();
        System.out.println("请输入客户购买家具的时间");
        String time=scanner.nextLine();
        Custom custom=new Custom(name,number,address,id,count,time);
        return customServicempl.modify(custom);
    }
    private static Custom getcustombyid(){ // 通过id进行查询信息
        Scanner scanner=new Scanner(System.in);
        System.out.println("请输入客户姓名:");
        String name=scanner.nextLine();
        return customServicempl.getcustombyid(name);
    }
    private static List<Custom> getall(){ //查询所有的信息
        return customServicempl.getall();
    }

}
